import {AfterContentInit, Component, ContentChildren, OnInit, QueryList, ViewEncapsulation} from '@angular/core';
import {TabComponent} from "./tab.component";

@Component({
  selector: 'ss-platform-tabs',
  templateUrl: './tabs.component.html',
  styleUrls: ['./tabs.component.scss'],
  host: {"class": "ss-platform-tabs-wraper"},
  encapsulation: ViewEncapsulation.None
})
export class TabsComponent implements OnInit, AfterContentInit {


  @ContentChildren(TabComponent)
  tabs: QueryList<TabComponent>;
  activeTab!: TabComponent;

  constructor() {
  }

  active(activeTab): void {
    this.tabs.forEach(tab => tab.isActive = false);
    this.activeTab = activeTab;
    this.activeTab.isActive = true;
  }

  ngOnInit(): void {
  }

  ngAfterContentInit(): void {
    setTimeout(() => {
      this.activeTab = this.tabs.find(tab => tab.isActive);
    })
  }

}
